package indi.mumu.validator;

import indi.mumu.common.model.Clothes;
import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

public class POSValidator extends Validator {
	
	protected void validate(Controller controller) {
		validateRequiredString("clothes.product_id", "productIdMsg", "请输入商品ID!");
		validateRequiredString("clothes.name", "nameMsg", "请输入商品名称!");
		validateRequiredString("clothes.barcode", "barcodeMsg", "请输入商品条形码!");
	}
	
	protected void handleError(Controller controller) {
		controller.keepModel(Clothes.class);
		
		String actionKey = getActionKey();
		if (actionKey.equals("/pos/save"))
			controller.render("add.html");
		else if (actionKey.equals("/pos/update"))
			controller.render("edit.html");
		else if (actionKey.equals("/pos/query"))
			controller.render("search.html");
		else if (actionKey.equals("/pos/query"))
			controller.render("sell.html");
	}
}
